//
//  WorkOrderPreview.m
//  WOPrototype
//
//  Created by Alexander Skogberg on 2010-04-15.
//  Copyright 2010 Chalmers tekniska högskola. All rights reserved.
//

// Because I'm lazy and someone decided to use a string for priority instead of an integer
#define priorities [NSArray arrayWithObjects:@"Låg", @"Medel", @"Brådskande", nil]
#define numArray [NSArray arrayWithObjects:[NSNumber numberWithInteger:0], [NSNumber numberWithInteger:1], [NSNumber numberWithInteger:2], nil]
#define priorityToInt [NSDictionary dictionaryWithObjects:numArray forKeys:priorities]

#import "WorkOrderPreview.h"

@implementation WorkOrderPreview

@synthesize workID;
@synthesize description;
@synthesize status;
@synthesize priority;
@synthesize address;
@synthesize entryDate;
@synthesize endDate;
@synthesize assigned;
@synthesize notAssignedToAnyone;

-(id) initWithWorkID:(NSInteger) aWorkID 
		 description:(NSString *) aDescription 
			  status:(NSString *) aStatus
			priority:(NSString *) aPriority 
			 address:(WOAddress *) anAddress 
		   entryDate:(NSDate *) anEntryDate
			 endDate:(NSDate *) anEndDate	
{
	if (self = [super init]) 
	{
		self.workID = aWorkID;
		self.description = aDescription;
		self.status = aStatus;
		self.priority = aPriority;
		self.address = anAddress;
		self.entryDate = anEntryDate;
		self.endDate = anEndDate;
	}
	return self;
}

/* Compare one work order preview with another */
- (NSComparisonResult) compare:(WorkOrderPreview*)other
{
	NSComparisonResult result = [[priorityToInt objectForKey:other.priority] compare:[priorityToInt objectForKey:self.priority]];
	if (result == 0)
		return [other.entryDate compare:self.entryDate];
	return result;
}

@end